<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="用户名:">
        <el-input v-model="form.uname"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input
          type="password"
          v-model="form.ukey"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item label="姓名:">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="部门:">
        <div class="block">
          <el-cascader
            :options="options"
            v-model="sz"
            :props="{ checkStrictly: true }"
            clearable
          ></el-cascader>
        </div>
      </el-form-item>
      <el-form-item label="角色:">
        <el-select v-model="form.rolejh" multiple placeholder="请选择">
          <el-option
            v-for="item in juese"
            :key="item.rid"
            :label="item.rname"
            :value="item.rid"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        uname: "",
        ukey: "",
        name: "",
        bmid: 0,
        isdelete: false,
        rolejh: [],
        token: sessionStorage.getItem("token"),
      },
      options: [],
      sz: [],
      juese: [],
    };
  },
  mounted() {
    var my = this;
    this.$axios
      .get("http://localhost:5230/api/item1/Getbm")
      .then(function (s) {
        my.options = s.data.modlist;
      });
    this.$axios
      .get("http://localhost:5230/api/item1/Getrole")
      .then(function (s) {
        my.juese = s.data.modlist;
      });
  },
  methods: {
    onSubmit() {
      var my = this;
      my.form.bmid = my.sz[my.sz.length - 1];
      alert(JSON.stringify(my.form));
      this.$axios
        .post("http://localhost:5230/api/item1/Postadd", my.form)
        .then(function (h) {
          if (h.data.h > 0) {
            alert("添加成功");
          } else {
            alert("添加失败");
          }
        });
    },
    handleChange(value) {
      console.log(value);
    },
  },
};
</script>